<html>
 <head>
  <title>Test Page for AddGestureWarlocksScript</title>
  <script type="text/javascript" language="javascript" src="../../../../../../jsunit/app/jsUnitCore.js"></script>
  <script type="text/javascript" language="javascript" src="../../main/js/AddGestureWarlocksScript.user.js"></script>
 </head>
 <body>
  <script type="text/javascript" language="javascript">
  	function assertEqualSpellArrays(expectedSpells, actualSpells)
  	{
    	assertEquals("Arrays should have the same length",
    		expectedSpells.length, actualSpells.length);
    	
    	for (var i=0; i<expectedSpells.length; i++)
    	{
    		assertTrue("Spells should be the same",
    			expectedSpells[i].equals(actualSpells[i]));
    	}
  	}
  	
  	function assertEqualArrayOfSpellArrays(expectedSpells, actualSpells)
  	{
  		assertEquals("Wrapping arrays should have the same length",
  			expectedSpells.length, actualSpells.length);
  		
  		for (var i=0; i<expectedSpells.length; i++)
  		{
  			assertEquals("Spell array " + i + " should have the same length",
  				expectedSpells[i].length, actualSpells[i].length);
  			
  			for (var j=0; j<expectedSpells[i].length; j++)
  			{
  				assertTrue("Spells indexed by " + i + ", " + j + " should be the same",
  					expectedSpells[i][j].equals(actualSpells[i][j]));
  			}
  		}
  	}
  
  	function testDetermineBothHandGestures()
  	{
  		var inputData = new Array();
  		inputData[0] = "CDPW>";
  		inputData[1] = "CSWWS";
  	
  		var expectedResult = new Array();
  		expectedResult[0] = "cDPw>";
  		expectedResult[1] = "cSWwS";
  		
  		var actualResult = determineBothHandGestures(inputData);
  		
  		assertEquals(expectedResult.length, actualResult.length);
  		assertEquals(expectedResult[0], actualResult[0]);
  		assertEquals(expectedResult[1], actualResult[1]);
  	}
  	
  	function testEvaluateGestures_WW()
  	{
  		var inputData = "WW";
  		
  		var expectedResult = new Array();
  		expectedResult[0] = new Array();
  		expectedResult[1] = new Array();
		expectedResult[1][0] = new Spell("WDDc", "+ Clap of Lightning");
		expectedResult[1][1] = new Spell("WFP", "Cause Light Wounds");
		expectedResult[1][2] = new Spell("WFPSFW", "Summon Giant");
		expectedResult[1][3] = new Spell("WPFD", "Cause Heavy Wounds");
		expectedResult[1][4] = new Spell("WPP", "Counter Spell");
		expectedResult[1][5] = new Spell("WSSc", "Ice Storm");
		
		expectedResult[2] = new Array();
		expectedResult[2][0] = new Spell("WWFP", "Resist Heat");
		expectedResult[2][1] = new Spell("WWP", "Protection");
		expectedResult[2][2] = new Spell("WWS", "Counter Spell");
		
		var actualResult = evaluateGestures(inputData);
		
		assertEqualArrayOfSpellArrays(expectedResult, actualResult);
	}
	
	function testEvaluateGestures_Fc()
	{
		var inputData = "Fc";
		var expectedResult = new Array();
		expectedResult[0] = new Array();
		expectedResult[1] = new Array();
		expectedResult[1][0] = new Spell("cDPW", "Dispel Magic");
		expectedResult[1][1] = new Spell("cSWWS", "Summon Ice Elemental");
		expectedResult[1][2] = new Spell("cWSSW", "Summon Fire Elemental");
		expectedResult[1][3] = new Spell("cw", "Magic Mirror");
		
		expectedResult[2] = new Array();
		
		var actualResult = evaluateGestures(inputData);
		
		assertEqualArrayOfSpellArrays(expectedResult, actualResult);
	}
	
	function testEvaluateGestures_cw()
	{
		var inputData = "cw";
		var expectedResult = new Array();
		expectedResult[0] = new Array();
		expectedResult[0][0] = new Spell("cw", "Magic Mirror");

		expectedResult[1] = new Array();
		expectedResult[1][0] = new Spell("WDDc", "+ Clap of Lightning");
		expectedResult[1][1] = new Spell("WFP", "Cause Light Wounds");
		expectedResult[1][2] = new Spell("WFPSFW", "Summon Giant");
		expectedResult[1][3] = new Spell("WPFD", "Cause Heavy Wounds");
		expectedResult[1][4] = new Spell("WPP", "Counter Spell");
		expectedResult[1][5] = new Spell("WSSc", "Ice Storm");
		expectedResult[1][6] = new Spell("WWFP", "Resist Heat");
		expectedResult[1][7] = new Spell("WWP", "Protection");
		expectedResult[1][8] = new Spell("WWS", "Counter Spell");

		expectedResult[2] = new Array();
		expectedResult[2][0] = new Spell("cWSSW", "Summon Fire Elemental");
		
		var actualResult = evaluateGestures(inputData);
		
		assertEqualArrayOfSpellArrays(expectedResult, actualResult);
  	}
  	
  	function testEvaluateGestures_InvisGestures_Fd()
  	{
  		var inputData = "???Fd";
  		var expectedResult = new Array();
  		expectedResult[0] = new Array();
  		expectedResult[0][0] = new Spell("WPFD", "Cause Heavy Wounds");
  		expectedResult[0][1] = new Spell("DFWFd", "Blindness");
  		expectedResult[0][2] = new Spell("DWFFd", "Blindness");
  		expectedResult[0][3] = new Spell("SPPFD", "Time Stop");
  		
  		expectedResult[1] = new Array();
  		expectedResult[1][0] = new Spell("DFPW", "Cure Heavy Wounds");
  		expectedResult[1][1] = new Spell("DFW", "Cure Light Wounds");
  		expectedResult[1][2] = new Spell("DPP", "Amnesia");
  		expectedResult[1][3] = new Spell("DSF", "Confusion/Maladroitness");
  		expectedResult[1][4] = new Spell("DSFFFc", "Disease");
  		expectedResult[1][5] = new Spell("DWSSSP", "Delay Effect");
  		expectedResult[1][6] = new Spell("DWWFWD", "Poison");
  		
  		expectedResult[2] = new Array();
  		expectedResult[3] = new Array();
  		
  		expectedResult[4] = new Array();
  		expectedResult[4][0] = new Spell("DFFDD", "Lightning Bolt");
  		
  		expectedResult[5] = new Array();
		
		var actualResult = evaluateGestures(inputData);
		
		assertEqualArrayOfSpellArrays(expectedResult, actualResult);
  	}
  	
    function testGetMatchedSpells()
    {
    	//TODO: How can object equality be done in javascript?
    	var expectedSpells = new Array();
		expectedSpells[0] = new Spell("DFFDD", "Lightning Bolt");
		expectedSpells[1] = new Spell("DFPW", "Cure Heavy Wounds");
		expectedSpells[2] = new Spell("DFW", "Cure Light Wounds");
		expectedSpells[3] = new Spell("DFWFd", "Blindness");
		expectedSpells[4] = new Spell("DPP", "Amnesia");
		expectedSpells[5] = new Spell("DSF", "Confusion/Maladroitness");
		expectedSpells[6] = new Spell("DSFFFc", "Disease");
		expectedSpells[7] = new Spell("DWFFd", "Blindness");
		expectedSpells[8] = new Spell("DWSSSP", "Delay Effect");
		expectedSpells[9] = new Spell("DWWFWD", "Poison");
    	
    	var matchedSpells = getMatchedSpells("D");
    	
    	assertEqualSpellArrays(expectedSpells, matchedSpells);
    }
    
    function testProcessPlayer()
    {
    	var expectedPlayer = new Player("Rasper", "PS", "WW");
    	
    	expectedPlayer.spells[0] = new Array();
    	expectedPlayer.spells[0][0] = new Array();
    	expectedPlayer.spells[0][1] = new Array();
		expectedPlayer.spells[0][1][0] = new Spell("SD", "Magic Missile");
		expectedPlayer.spells[0][1][1] = new Spell("SFW", "Summon Goblin");
		expectedPlayer.spells[0][1][2] = new Spell("SPFP", "Anti-spell");
		expectedPlayer.spells[0][1][3] = new Spell("SPFPSDW", "Permanency");
		expectedPlayer.spells[0][1][4] = new Spell("SPPc", "Time Stop");
		expectedPlayer.spells[0][1][5] = new Spell("SPPFD", "Time Stop");
		expectedPlayer.spells[0][1][6] = new Spell("SSFP", "Resist Cold");
		expectedPlayer.spells[0][1][7] = new Spell("SWD", "Fear (No CFDS)");
		expectedPlayer.spells[0][1][8] = new Spell("SWWc", "Fire Storm");

    	expectedPlayer.spells[0][2] = new Array();
		expectedPlayer.spells[0][2][0] = new Spell("PSDD", "Charm Monster");
		expectedPlayer.spells[0][2][1] = new Spell("PSDF", "Charm Person");
		expectedPlayer.spells[0][2][2] = new Spell("PSFW", "Summon Ogre");

		expectedPlayer.spells[1] = new Array();
    	expectedPlayer.spells[1][0] = new Array();
    	expectedPlayer.spells[1][1] = new Array();
		expectedPlayer.spells[1][1][0] = new Spell("WDDc", "+ Clap of Lightning");
		expectedPlayer.spells[1][1][1] = new Spell("WFP", "Cause Light Wounds");
		expectedPlayer.spells[1][1][2] = new Spell("WFPSFW", "Summon Giant");
		expectedPlayer.spells[1][1][3] = new Spell("WPFD", "Cause Heavy Wounds");
		expectedPlayer.spells[1][1][4] = new Spell("WPP", "Counter Spell");
		expectedPlayer.spells[1][1][5] = new Spell("WSSc", "Ice Storm");

    	expectedPlayer.spells[1][2] = new Array();
		expectedPlayer.spells[1][2][0] = new Spell("WWFP", "Resist Heat");
		expectedPlayer.spells[1][2][1] = new Spell("WWP", "Protection");
		expectedPlayer.spells[1][2][2] = new Spell("WWS", "Counter Spell");
		
    	var actualPlayer = processPlayer(expectedPlayer);
    	
    	assertEqualArrayOfSpellArrays(expectedPlayer.spells[0], actualPlayer.spells[0]);
    	assertEqualArrayOfSpellArrays(expectedPlayer.spells[1], actualPlayer.spells[1]);
    }
    
    function testProcessWarlocksPage()
    {
    	processWarlocksPage();
    }
    
    function testRemovePreviouslyMatchedSpells()
    {
    	var spell = new Spell("DFFDD", "Lightning Bolt");
    	var matchedSpells = new Array();
    	matchedSpells[0] = new Array();
    	
    	matchedSpells[1] = new Array();
    	matchedSpells[1][0] = new Spell("DFFDD", "Lightning Bolt");
    	matchedSpells[1][1] = new Spell("DSF", "Confusion/Maladroit");
    	
    	matchedSpells[2] = new Array();
    	
    	matchedSpells[3] = new Array();
    	
    	var expectedResult = new Array();
    	expectedResult[0] = new Array();
    	
    	expectedResult[1] = new Array();
    	expectedResult[1][0] = new Spell("DSF", "Confusion/Maladroit");
    	
    	expectedResult[2] = new Array();
    	
    	expectedResult[3] = new Array();
    
    	var actualResult = removePreviouslyMatchedSpells(spell, matchedSpells);
    	
    	assertEqualArrayOfSpellArrays(expectedResult, actualResult);
    }
    
    function testSpellEquals()
    {
    	var spell1 = new Spell("DSF", "This spell");
    	var spell2 = new Spell("DSF", "This spell");
    	
    	assertTrue(spell1.equals(spell2));
    }

    function testTrimInvalidGestures()
    {
    	assertEquals("DC", trimInvalidGestures("ABDC"));
    	assertEquals("-PSF>", trimInvalidGestures(" -PSZFB>"));
    	assertEquals("PSDF", trimInvalidGestures(":Bpsdf "));
    }

  </script>

<TABLE WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
	<TD>google ads</td>
	<TD ALIGN=RIGHT class=transbg><A HREF="/logout">Log out Rasper</A></TD>
</TR>
</TABLE>


<TABLE BORDER=0 WIDTH="100%" CELLPADDING=4 CELLSPACING=0>
<TR>
	<TD ALIGN=LEFT VALIGN=MIDDLE CLASS=lightbg>
		<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=4>
		<TR>
			<TD WIDTH=100 ALIGN=CENTER>
				<H2><A HREF="/rules/0/index.html">Rules</A></H2>
			</TD>
			<TD WIDTH=100 ALIGN=CENTER>
				<H2><A HREF="/player">Status</A></H2>
			</TD>
			<TD WIDTH=100 ALIGN=CENTER>
				<H2><A HREF="/challenges">Challenges</A></H2>
			</TD>
			<TD WIDTH=100 ALIGN=CENTER>
				<H2><A HREF="/players">Players</A></H2>
			</TD>
		</TR>
		</TABLE>
	</TD>
	<TD ALIGN=RIGHT VALIGN=MIDDLE CLASS=lightbg>
		<H1><A HREF="/">RavenBlack Games</A></H1>
	</TD>
</TR>
</TABLE>


<BR>
<DIV ALIGN=RIGHT><A TARGET=_blank HREF="/rules/1/quickref.html">Spell Reference</A></DIV><H2><U>Turn 4 in Friendly Battle 54978</U></H2><BR><BLOCKQUOTE><FONT COLOR="#CCCCCC">mpchatty snaps the fingers of his left hand.<BR>

mpchatty snaps the fingers of his right hand.<BR>
</FONT><FONT COLOR="#88FF88">mpchatty casts Invisibility at himself.</FONT><BR>
<FONT COLOR="#CCCCCC">Rasper wiggles the fingers of his left hand.<BR>
Rasper proffers the palm of his right hand.<BR>
</FONT><FONT COLOR="#88FF88">Rasper casts Counter Spell at mpchatty.</FONT><BR>
<FONT COLOR="#CCCCCC">PWPFSSSD wiggles the fingers of his left hand.<BR>
PWPFSSSD waves his right hand.<BR>
</FONT><FONT COLOR="#CCCCCC">Kenton wiggles the fingers of his left hand.<BR>
Kenton proffers the palm of his right hand.<BR>

</FONT><FONT COLOR="#88FF88">Kenton casts Resist Heat at himself.</FONT><BR>
<FONT COLOR="#88FFFF">mpchatty is covered by a magical glowing shield.</FONT><BR>
<FONT COLOR="#88FFFF">Kenton is covered in a coat of sparkling frost.</FONT><BR>
<FONT COLOR="#88AAFF">mpchatty's shield disappears for a moment.</FONT><BR>
PWPFSSSD directs Green Goblin to attack mpchatty.<BR>
<FONT COLOR="#88AAFF">Green Goblin attacks mpchatty, but is deflected by a shield.</FONT><BR>
</BLOCKQUOTE>
<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="100%">
<TR>
	<TD CLASS=lightbg WIDTH="50%">Green Goblin</TD>
	<TD CLASS=lightbg>Health:1</TD>
</TR>
<TR>
	<TD>Owned by: PWPFSSSD</TD>
	<TD>Attacking: mpchatty</TD>
</TR>
</TABLE>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="100%">
<TR>
	<TD CLASS=lightbg WIDTH="50%"><a href="/player/mpchatty.html">mpchatty</A>(0) (awaiting orders)</TD>
	<TD CLASS=lightbg>Health:15</TD>
</TR>
<TR>
	<TD COLSPAN=2>
		<FONT CLASS=monoturn>Turn:</FONT>
		<A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=0">0</A>
		<A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=1">1</A>
		<A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=2">2</A>
		<A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=3">3</A>
		<A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=4">4</A>
		<BR>
		<FONT CLASS=monoturn>&nbsp;&nbsp;LH:</FONT>
		<FONT CLASS=monoturn>BSFWS</FONT>
		<BR>
		<FONT CLASS=monoturn>&nbsp;&nbsp;RH:</FONT>
		<FONT CLASS=monoturn>BPPWS</FONT>
	</TD>
</TR>
</TABLE>
<BR>
<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="100%"><TR><TD CLASS=lightbg WIDTH="50%"><a href="/player/PWPFSSSD.html">PWPFSSSD</A>(0) (awaiting orders)</TD><TD CLASS=lightbg>Health:15</TD></TR><TR><TD COLSPAN=2>

<FONT CLASS=monoturn>Turn:</FONT><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=0">0</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=1">1</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=2">2</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=3">3</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=4">4</A><BR><FONT CLASS=monoturn>&nbsp;&nbsp;LH:</FONT><FONT CLASS=monoturn>BSFWF</FONT><BR><FONT CLASS=monoturn>&nbsp;&nbsp;RH:</FONT><FONT CLASS=monoturn>BSFWW</FONT></TD></TR></TABLE><BR>
<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="100%"><TR><TD CLASS=lightbg WIDTH="50%"><a href="/player/Kenton.html">Kenton</A>(0) (awaiting orders)</TD><TD CLASS=lightbg>Health:15 - Fireproof(permanent) </TD></TR><TR><TD COLSPAN=2>
<FONT CLASS=monoturn>Turn:</FONT><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=0">0</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=1">1</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=2">2</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=3">3</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=4">4</A><BR><FONT CLASS=monoturn>&nbsp;&nbsp;LH:</FONT><FONT CLASS=monoturn>B-SSF</FONT><BR><FONT CLASS=monoturn>&nbsp;&nbsp;RH:</FONT><FONT CLASS=monoturn>BWWFP</FONT></TD></TR></TABLE><BR>

<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 WIDTH="100%"><TR><TD CLASS=lightbg WIDTH="50%"><a href="/player/Rasper.html">Rasper</A>(0)</TD><TD CLASS=lightbg>Health:15 - Shield(1) </TD></TR><TR><TD COLSPAN=2>
<FONT CLASS=monoturn>Turn:</FONT><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=0">0</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=1">1</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=2">2</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=3">3</A><A CLASS=amonoturn HREF="/warlocks?num=54978&amp;turn=4">4</A><BR><FONT CLASS=monoturn>&nbsp;&nbsp;LH:</FONT><FONT CLASS=monoturn>BSFWF</FONT><BR><FONT CLASS=monoturn>&nbsp;&nbsp;RH:</FONT><FONT CLASS=monoturn>BWWPP</FONT></TD></TR></TABLE><BR>
<BR>Your orders are in for this turn.<BR><BR><FONT COLOR="#AAAAAA">LH: P (default spell at mpchatty).</FONT><BR>

<FONT COLOR="#AAAAAA">RH: S</FONT><BR>

 </body>
</html>